from rich.console import Console
from rich.progress import Progress
import time, os, shutil

__version__ = '0.0.1'
console = Console()

def Iscon(op, np, con=console):
    if not os.path.exists(op):
        con.print('[bold red]Target Not Exist.')
        return False
    if (not os.path.exists(np)) or (not os.path.isdir(np)):
        try:os.makedirs(np)
        except:
            con.print('[bold red]Folder Can\'t be Created.')
            return False
    return True

def Move(op, np, con=console):
    if not Iscon(op, np, con):return False
    path, name = os.path.split(op)
    if os.path.isfile(op):
        con.print('[bold]Move File [bold blue]{}.'.format(name))
        np = os.path.join(np, name)
    if os.path.isdir(op):
        con.print('[bold]Move Folder [bold blue]{}.'.format(op))
        t = op.replace('\\', '/').split('/')[-1]
        np = os.path.join(np, t)
    try:
        with console.status('[bold blue]Moving...[/]'):
            shutil.move(op, np)
        con.print('[bold green]Successfully.')
    except:
        con.print('[bold red]Failed.')

def Copy(op, np, con=console):
    if not Iscon(op, np, con):return False
    path, name = os.path.split(op)
    mode = 0
    if os.path.isfile(op):
        mode = 1
        con.print('[bold]Copy File [bold blue]{}.'.format(name))
        np = os.path.join(np, name)
    if os.path.isdir(op):
        mode = 2
        con.print('[bold]Copy Folder [bold blue]{}.'.format(op))
        t = op.replace('\\', '/').split('/')[-1]
        np = os.path.join(np, t)
    try:
        with console.status('[bold blue]Moving...[/]'):
            if mode == 1:
                shutil.copy(op, np)
            else:
                shutil.copytree(op, np)
        con.print('[bold green]Successfully.')
    except:
        con.print('[bold red]Failed.')
        